﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using Com.Oxilly.Qsb.Core.SDK.EF;

namespace ScanTester
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            try
            {
                Console.ReadLine();
                p.ScanForExtensions();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }

        internal void ScanForExtensions()
        {
            //Scan for dll's in a configured directory, use reflextion to find Extensions

            var fullPath = Assembly.GetExecutingAssembly().Location;
            var path = fullPath.Substring(0, fullPath.LastIndexOf(@"\"));
            var qAppPath = path + @"\..\QApps\";
            //Log(String.Format("Klaarmaken voor scannen QApps in '{0}'.", qAppPath));
            var dirs = Directory.GetDirectories(qAppPath);
            foreach (var dir in dirs)
            {
                //Log(String.Format("Bezig met scannen van directory '{0}'.", dir));
                var dlls = Directory.GetFiles(dir, @"*.dll");
                foreach (var dll in dlls)
                {
                    //Log(String.Format("Bezig met scannen van ddl '{0}'.", dll));

                    var assembly = Assembly.LoadFrom(dll);
                    var qAppTypes = assembly.GetTypes().Where(t => typeof(Com.Oxilly.Qsb.Core.SDK.EF.QAppBase).IsAssignableFrom(t));
                    foreach (var qAppType in qAppTypes)
                    {
                        try
                        {
                            //Log(String.Format("Bezig met aanmaken QApp '{0}'.", qAppType.FullName));
                            var qApp = Activator.CreateInstance(qAppType) as QAppBase;
                            //InstallExtension(qApp);
                        }
                        catch
                        {
                            
                        }
                    }
                }
            }
        }
    }
}
    

